//
//  ProgressButton.m
//  SessionTask
//
//  Created by 马滕亚 on 2020/4/4.
//  Copyright © 2020 M.Y.A. All rights reserved.
//

#import "ProgressButton.h"

@implementation ProgressButton

- (void)setProgress:(CGFloat)progress {
    _progress = progress;
    [self setTitle:[NSString stringWithFormat:@"%.02f%%",progress*100] forState:UIControlStateNormal];

    // 刷新视图
    [self setNeedsDisplay];
    
}

- (void)drawRect:(CGRect)rect {
    
    /** 参数
     * 圆心
     * 半径
     * 起始角度 (OC 中 起始位置是在时钟三点钟的位置)
     * 结束角度
     * 是否顺时针
     */
    CGSize size = rect.size;
    CGPoint center = CGPointMake(size.width * 0.5, size.height * 0.5);
    CGFloat r = (size.height > size.width) ? size.width * 0.5 : size.height * 0.5;
    r -= 3.0;
    CGFloat startAng = -M_PI_2;
    CGFloat endAng = self.progress * 2 * M_PI + startAng;
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:r startAngle:startAng endAngle:endAng clockwise:YES];
    // 设置线条宽度
    path.lineWidth = 6.0;
    path.lineCapStyle = kCGLineCapRound;
    path.lineJoinStyle = kCGLineJoinRound;
    
    [[UIColor greenColor] setStroke];
    // 绘制路径
    [path stroke];
    
    
}














@end
